package com.config;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * <p>
 *     注册拦截器
 * </p>
 * @author zdh
 */
@Configuration
@RequiredArgsConstructor
public class MyWebMvcConfigurer implements WebMvcConfigurer {
  private final IpHandlerInterceptor ipHandlerInterceptor;
  private final ManagerHandlerInterceptor managerHandlerInterceptor;
  /**
   * 拦截器匹配路径不包含父项目路径
   */
  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(ipHandlerInterceptor).addPathPatterns("/**").excludePathPatterns(
            "/doc.html", "/css/**", "/fonts/**", "/images/**", "/js/**","/webjars/**",
            "/doc.html#/**","/swagger-resources","/v3/**","/hot/**","/manager/**");
    //只拦截后台请求
    registry.addInterceptor(managerHandlerInterceptor).addPathPatterns("/manager/**");
  }
}
